// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境
const db=cloud.database();
// 云函数入口函数
exports.main = async (event, context) => {
  switch(event.type){
    // 根据id查找对应老人的健康数据
    case 'selectById':
      return await db.collection("health").where({
        pid:event.id
      }).get()
      //上传老人数据
case "count":
  return await db.collection("health").where({
    pid:event.id
  }).count()

      case 'add':
        return await db.collection("health").add({
          data:{
            acid:event.acid,
            glucose:event.glucose,
            lipid:event.lipid,
            weight:event.weight,
            pressure:event.pressure,
            temperature:event.temperature,
            heart:event.heart,
            time:event.time,
            pid:event.oldid
          }
        })
        case 'update':
          return await db.collection("health").where({
            pid:event.oldid,
          }).update({
            data:{    
              acid:event.acid,
              glucose:event.glucose,
              lipid:event.lipid,
              weight:event.weight,
              pressure:event.pressure,
              temperature:event.temperature,
              heart:event.heart,
              time:event.time,
              pid:event.oldid
            }
          })
      
    }
}